<?php

class FeeCalculator  {

    private $rateInfoProperties;
    private $state;

    public function FeeCalculator($state, $rateInfoProperties) {
        $this->rateInfoProperties = $rateInfoProperties;
        $this->state = $state;
    }

    // why not add one more line for "Recording Fee" which would either be $40 for a deed of trust for a primary
    // residence of $95 for a non-primary residence and if a purchase, add another $40 for deed recording. of course,
    // when you allow the user to select whether there are one or two new loans, the charge would reflect the
    // appropriate charge for each new loan (e.g. - $40 each or $95 each based on whether the property is a primary
    // residence). there will be additional taxes other than recordation tax in pg county if the purchase money
    // record has been on record for less than 12 months.

    public function calculate($purchase, $mortgage, $ownerOccupiedResidence) {
         $fees = array();

        // CT-32 Deed would be charged when there is a purchase transaction.
        // A Deed of trust would be charged on a purchase transaction if there is a loan amount. You will need to know,
        // therefore, if there is a loan amount on a purchase. I added a note regarding title insurance where I realize
        // you need a box for loan amount for purchase transactions or you will need to use the existing loan amount box
        // even when the transaction is a purchase transaction.
        // In a refinance transaction, there is no charge for a deed but always a charge for a deed of trust.

        //Deed	 Deed of Trust/Mortgage 
        //Maryland
        //Primary Residence	 40	 40
        //Investment Property	 40	 95
         //echo "$purchase - $mortgage"; exit();
        if ($purchase) {
            $fees[] = $this->rateInfoProperties->getPurchaseFee($this->state);
        }
        if ($mortgage > 0) {
            if ($ownerOccupiedResidence != null && $ownerOccupiedResidence->getValue()) {
                $fees[] = new Fee($this->rateInfoProperties->getMortgageFeeName($this->state), 
                $this->rateInfoProperties->getMortgagePrimaryResidenceFeeValue($this->state) * $mortgage);
            } else {
                $fee = $this->rateInfoProperties->getMortgageFee($this->state);
                $fees[] = new Fee($fee->getName(), $fee->getAmount() * $mortgage);
            }
        }
        //print_r($fees); exit();

        return $fees;
    }
}

?>
